package com.lzy.mall.search.controller;

import com.lzy.mall.search.service.MallSearchService;
import com.lzy.mall.search.vo.SearchParam;
import com.lzy.mall.search.vo.SearchResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lzy
 * @date 2021/9/14 14:06
 */
@Controller
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class SearchController {

    private final MallSearchService searchService;

    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){

        // 获取路径原生的查询属性
        param.set_queryString(request.getQueryString());

        SearchResult result = searchService.search(param);

        model.addAttribute("result",result);
        return "list";
    }
}
